/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { isLegalData } from '@/utils/utils';
import request from '../utils/request';

// 中邮获取左侧公司列表
export async function zyGetCompaniesList(params) {
  return request('/Api/ChinaPost/Branch/subBranch', {
    method: 'POST',
    body: params,
    allowConcurrent: true, // 允许并发请求
  });
}
// 中邮获取右侧账号列表
export async function zyGetAcountsList(params) {
  return request('/Api/ChinaPost/Account/list', {
    method: 'POST',
    body: params,
  });
}
// 中邮，修改账号权限及删除
export async function zySwitchStatus(params) {
  return request('/Api/ChinaPost/Account/status', {
    method: 'POST',
    body: params,
  });
}
// 中邮，添加及编辑账号
export async function zySave(params) {
  return request('/Api/ChinaPost/Account/save', {
    method: 'POST',
    body: params,
  });
}
// 中邮，权限设置
export async function zyPrivilegeSet(params) {
  return request('/Api/ChinaPost/Account/privilegeSetting', {
    method: 'POST',
    body: params,
  });
}
// 中邮，获取下属驿站
export async function zyGetSubPostStations(params) {
  return request('/Api/ChinaPost/Dak/subDak', {
    method: 'POST',
    body: params,
  });
}
// 中邮，获取待审核驿站列表
export async function zyGetSubPostStationsToBeChecked(params) {
  return request('/Api/ChinaPost/Dak/waitingAudit', {
    method: 'POST',
    body: params,
  });
}
// 中邮，禁用或恢复驿站
export async function zyForbidOrRecover(params) {
  return request('/Api/ChinaPost/Dak/setAble', {
    method: 'POST',
    body: params,
  });
}
// 中邮，审核驿站（通过或拒绝）
export async function zyAudit(params) {
  return request('/Api/ChinaPost/Dak/checkSub', {
    method: 'POST',
    body: params,
  });
}
// 中邮，添加支局
export async function zyAddBranch(params) {
  return request('/Api/ChinaPost/Branch/addBranch', {
    method: 'POST',
    body: params,
  });
}
/**
 * 中邮，编辑支局
 *  */
export async function zyEditBranch(params) {
  return request('/Api/ChinaPost/Branch/editBranch', {
    method: 'POST',
    body: params,
  });
}
// 中邮，下属驿站修改支局
export async function zyChangeBranch(params) {
  return request('/Api/ChinaPost/Dak/changeBranch', {
    method: 'POST',
    body: params,
  });
}
// 共配权限，获取省级公司
export async function zyGetProvinces(params) {
  return request('/Api/ChinaPost/ZyGpJur/getProvincial', {
    method: 'POST',
    body: params,
  });
}
// 共配权限，获取市级公司
export async function zyGetCities(params) {
  return request('/Api/ChinaPost/ZyGpJur/getCity', {
    method: 'POST',
    body: params,
  });
}

// 中邮导出
export async function zyExport(params) {
  return request('/Api/YZ/CourierStation/exportAllInn', {
    method: 'POST',
    body: params,
  });
}

// 下属驿站，获取片区列表
export async function getTownList(params) {
  return new Promise(resolve => {
    request('/Api/ChinaPost/Branch/getTownshipBranch', {
      method: 'POST',
      body: params,
    })
      .then((res = {}) => {
        const { code, data = [] } = res;
        if (code == 0) {
          resolve(isLegalData(data));
        } else {
          resolve([]);
        }
      })
      .catch(() => {
        resolve([]);
      });
  });
}
